<?php

include("application/base_class.php");
$base_obj = new BaseClass();

$module =  $_POST['module'];
$process =  $_POST['process'];

switch($module) {
	case 'classifieds':
		switch($process) {
			case 'post_ads':
				if($_POST['listinglevel'] == 1)
				{
					$amount = 10;
					$duration = 28;
				}
				else
				{
					$amount = 15;
					$duration = 28;
				}
				$post_array = array(
				    'Item'           =>  $_POST['item'],
					'Description'    =>  $_POST['desc'],
					'Category'       =>  $_POST['category'],
					'sub_category'   =>  $_POST['sub_category'],
					'ListingLevel'   =>  $_POST['listinglevel'],
					'ContactEmail'   =>  $_POST['contactemail'],
					'ShowEmail'      =>  $_POST['showcontactemail'],
					'Address1'       =>  $_POST['address1'],
					'Address2'       =>  $_POST['address2'],
					'City'           =>  $_POST['city'],
					'State'          =>  $_POST['state'],
					'Postcode'       =>  $_POST['postcode'],
					'Phone'          =>  $_POST['phone'],
					'Fax'            =>  $_POST['fax'],
					'BusinessDesc'   =>  $_POST['businessdesc'],
					'InsertedBy'     =>  '',
					'InsertedDate'   =>  gmdate('Y-m-d H:i:s'),
					'TransactionId'  =>  'user',
					'TotalAmount'    =>  $amount,
					'Duration'       =>  $duration,
					'Cust'           =>  'customer',
					'Status'         =>  '0',
					 );
				
				
			$path = "uploads/adimages/";
			$thumb_path = "uploads/adimages/thumb/";

			for($i=1;$i<=count($_FILES);$i++) {

				if($_FILES['tempimage'.$i]['name'] != "" and ($_FILES['tempimage'.$i]['type'] == "image/gif" || $_FILES['tempimage'.$i]['type'] == "image/pjpeg" || $_FILES['tempimage'.$i]['type'] == "image/jpeg") || ($_FILES['tempimage'.$i]['type'] == "image/png")) {

					$temp_name = str_replace($spl_char, "", $_FILES['tempimage'.$i]['name']);
					$temp_name =  preg_replace("([.]+)",".",$temp_name);
					
					$photos_pic_stored_name = mktime(date("H"), date("i"), date("s"), date("n"), date("j"), date("Y"))."_".$temp_name;
					move_uploaded_file($_FILES['tempimage'.$i]['tmp_name'], $path.$photos_pic_stored_name);
					
					$post_array['TempImage'.$i] = $photos_pic_stored_name;
				}
			}
			$base_obj->insert_query($base_obj->CLASSIFIEDS_ADS,$post_array);
				$e = mysql_fetch_array(mysql_query("select * from users where Id='$uid'"));
						$email = "ida@ecstasoft.com";;
						$from = "From: <$email>";
							$to = $_POST['contactemail'];
							$subject = "New Ad is submitted in Study sage";
							$message = "
			Hello,
			
			A new Ad is submitted in Study sage.
			
			Submited By:".$e['FirstName']." ".$e['LastName']."
			
			Please login using the below link to approve it.
			
			".$pathu_admin."
			
			";
		
			mail($to, $subject, $message, $from);

			echo '<script>location.href="index.php?page=thanks"</script>';
			break;
		}		
		break;
}
?>